﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL = LivroBebe.Business;
using Ent = LivroBebe.Model;

namespace LivroBebe
{
    public partial class LivroBebe : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ListaMenu();
        }

        private void ListaMenu() {
            StringBuilder strMenu = new StringBuilder();
            List<Ent.Menu> listaMenu = BLL.Menu.CarregaMenu();
            strMenu.AppendLine(@"<ul id='menu' class='menu'>");
            foreach (Ent.Menu menu in listaMenu)
            {
                strMenu.AppendLine(@"<li class='" + menu.CSS + "'><a href='' rel='" + menu.CSS + "'>" + menu.Titulo + "</a>");
                if (menu.MenuItem.Count > 0){
                    strMenu.AppendLine(@"<div class='navList' id='mItem_"+ menu.CSS +"' style='left:-" + (115 * (listaMenu.IndexOf(menu))) + "px'><ul>");
                    switch(menu.TipoMenu){
                        case 1:
                            foreach (Ent.MenuItem menuitem in menu.MenuItem)
                            {
                                strMenu.AppendLine(@"<li><a href=''>" + menuitem.Titulo + "</a></li>");
                                foreach (Ent.MenuItemNivel menuItemNivel in menuitem.MenuItemNivel)
                                    strMenu.AppendLine(@"<li><a href=''>" + menuItemNivel.Titulo + "</a></li>");
                            }
                            break;
                        case 2:
                            foreach (Ent.MenuItem menuitem in menu.MenuItem)
                                strMenu.AppendLine(@"<li><a href=''><p class='lpublic'><img src='" + menuitem.Imagem + "'/></p></a></li>");
                            strMenu.AppendLine(@"<p class='vermais'><a href=''>Ver mais...</a></p>");
                            break;
                    }
                    strMenu.AppendLine(@"</ul></div>");
                }                
            }
            strMenu.AppendLine(@"</ul>");
            LtlMenu.Text = strMenu.ToString();  
        }
    }
}